from starlette.middleware.base import BaseHTTPMiddleware


class JsonResponseMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request, call_next):
        response = await call_next(request)
        # 确保 Content-Type 为 JSON 且使用 UTF-8 编码
        response.headers["Content-Type"] = "application/json; charset=utf-8"
        return response